<?php

function __autoload( $class )
{
	require_once "{$class}.php";
}
header( "content=\"text/html; charset=uft-8\"" );
$memcache = new Memcache();
$memcache->connect( "127.0.0.1" , 11211 );
 $memcache->flush();
    $memcache->add( "person" , serialize( new Person( 'whq' ) ) );
    $memcache->add( "forest" , serialize( Forest::getInstance() ) );
$person = unserialize( $memcache->get( "person" ) );
$forest = unserialize( $memcache->get( "forest" ) );
$tmpForest = Forest::getInstance();
$tmpForest = clone $forest;
$tmp = 0;
$person->setSex( "男" );
//壮大森林
ini_set("max_execution_time", 3600);
while ( $tmp < 2000000 )
{
	$tmp++;
	$forest->grow();
	echo "<br />第{$tmp}次生长，树的数量：". $forest->getTreesNum();
}
/*echo $forest->getTreesNum() . "<br />";
$forest->grow();
$woodTrees = $person->whichCanBeCut( $forest );
echo "树木数量：" . $forest->getTreesNum() . "<br />";
echo count( $woodTrees ) . "<br />";
while ( $tmp < 3 && $woodTrees )
{
	$tmp++;
	foreach ( $woodTrees as $key )
	{
		if( isset( $forest[ $key ] ) )
		{
			$person->cutTree( $key );
		}
	}
}
echo "树木数量：" . $forest->getTreesNum() . "<br />";
echo count( $person->whichCanBeCut() ) . "<br />";
echo "人类拥有的木材数量：" . $person->checkSupply( 'wood' ) . "<br />";
Forest::getInformation( $forest );
$person->getInformation();*/
$memcache->replace( "person" , serialize( $person ) , MEMCACHE_COMPRESSED );
$memcache->replace( "forest" , serialize( $forest ) , MEMCACHE_COMPRESSED );
    